<?php
/*
	提现
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 * $Id: 2017-12-13 03:39:35 apple $
*/
defined('BY_JYA') or exit('error');
global $_RQ;
$_RQ['op']=$_RQ['op']?$_RQ['op']:'get';
cfc('core')->checklogin();
if($_RQ['op']=='get'){
	$pid=intval($_RQ['pid']);
	if(!$pid && $_RQ['id']){
		if(!$_RQ['type']){
			$url='jy_jifee_chu';
		}else{
			$url='jy_jifee_add';
		}	
		$return['post']=pdo_get($url,array('id'=>$_RQ['id'],'uniacid'=>$_SESSION['uniacid']));
		$return['post']['type']=$_RQ['type'];
		$pid=$return['post']['pid'];
	}else{
		$return['post']=array('type'=>0,'pid'=>$pid,'days'=>date('Y-m-d'));
	}
	if(!$pid){
		exi('请选择账本！','erroe');
	}
	
	$member=pdo_get('core_members',array('id'=>$_SESSION['uid']));
	$info=pdo_get('jy_jifee_list',array('id'=>$pid,'uniacid'=>$_SESSION['uniacid']));
	if($info['mid']!=$_SESSION['uid']){
		$this->model('model')->check_sub($pid);
	}
	$return['item']=$item;
	$return['member']=$member;
	$return['groups']=pdo_getall('jy_jifee_group',array('uniacid'=>$_SESSION['uniacid']));
	
	$return['sharedata']=array(
		'title'=>$info['title'],
		'desc'=>$info['desc'],
		'link'=>custom_url('jy_jifee/item//id='.$info['id'].'&fromuser='.$_SESSION['uid'],true),
		'imgUrl'=>$return['pluginset']['share_image']?tomedia($return['pluginset']['share_image']):tomedia($return['pluginset']['icon'])
	);
	set_html('title','记账');
	exi($return);
}
if($_RQ['op']=='post'){
	$post=get_postdata();
	if(!$post['fee']){
		exi('请输入金额！','erroe');
	}
	if(!$post['groupid']){
		exi('选择费用类型！','erroe');
	}
	if(!$post['days']){
		exi('选择日期！','erroe');
	}
	if(!$post['type']){
		$url='jy_jifee_chu';
	}else{
		$url='jy_jifee_add';
	}
	$post['days']=strtotime($post['days']);
	$data=array(
		'fee'=>trim($post['fee']),
		'desc'=>trim($post['desc']),
		'days'=>date('Y-m-d',$post['days']),
		'daytime'=>$post['days'],
	);
	$months=date('Y-m',$post['days']);
	$ismonths=pdo_get('jy_jifee_month',array('months'=>$months,'uniacid'=>$_SESSION['uniacid']),'id');
	if(!$ismonths){
		$monthdata=array(
			'uniacid'=>$_SESSION['uniacid'],
			'pid'=>trim($post['pid']),
			'mid'=>$_SESSION['uid'],
			'months'=>$months,
			'monthtime'=>strtotime($post['months']),
			'createtime'=>TIMESTAMP,
		);
		pdo_insert('jy_jifee_month',$monthdata);
	}
	$id=intval($post['id']);
	if($id){
		pdo_update($url,$data,array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
		exi('修改成功！','','/item//id='.$post['pid']);
	}else{
		$data['uniacid']=$_SESSION['uniacid'];
		$data['mid']=$_SESSION['uid'];
		$data['pid']=$post['pid'];
		$data['groupid']=$post['groupid'];
		$data['createtime']=TIMESTAMP;
		pdo_insert($url,$data);
		exi('添加成功！','','/item//id='.$post['pid']);
	}
}